package com.wyzz.hr.action;

import javax.servlet.http.HttpServletRequest;
import org.apache.axis.utils.StringUtils;
import org.apache.struts2.ServletActionContext;

import com.wyzz.hr.base.wf.leaverequest.LrWfApproverAction;
import com.wyzz.hr.bo.ILeaverequestBO;
import com.wyzz.hr.pojo.Employee;
import com.wyzz.hr.util.Pager;
import com.wyzz.hr.vo.ExaminSearchBean;
import com.wyzz.hr.vo.LeaveFormBean;

public class DeptLeaveSearchAction extends LrWfApproverAction {

	public DeptLeaveSearchAction() {
		role = "dept";
	}

	public String execute() throws Exception {
		initLRLists();
		actionSrc = "deptLeaveSearch.action";
		srcAction = "deptLeaveSearch";
		Employee currentEmp = getCurrentEmp();
		if (page == null) {
			page = new Pager();
			page.setOrder("");
		} else if (page.getOrder().trim().length() == 0)
			page.setOrder("");
		if (es_Bean == null)
			es_Bean = new ExaminSearchBean();
		setLeaveType(dbConfigManager.getProperty("sys.examin.leave.type"));
		ILeaverequestBO lr_BO = (ILeaverequestBO) getBean("leaverequestBO");
		lr_BO.approverMgrSearch(es_Bean, currentEmp, page);
		if (!StringUtils.isEmpty(infoMeg))
			addSuccessInfo(infoMeg);
		return "success";
	}

	public String deptApproveOrReject() throws Exception {
		String Ids[] = ServletActionContext.getRequest().getParameterValues(
				"changIds");
		String auth = checkActionAuth("deptLeaveSearch", "execute");
		String operate = approveOper;
		if ("ALL".equals(auth))
			operate = (new StringBuilder()).append("gm-").append(operate)
					.toString();
		if ("SUB".equals(auth))
			operate = (new StringBuilder()).append("mgr-").append(operate)
					.toString();
		return wfObjOpBatch(operate, lf_Bean, Ids);
	}

	public String deptApproveOrRejectWithModify() {
		if (lf_Bean == null)
			return "error";
		String auth = checkActionAuth("deptLeaveSearch", "execute");
		String operate = "approve".equals(approveOper) ? "modify" : "reject";
		if ("ALL".equals(auth))
			operate = (new StringBuilder()).append("gm-").append(operate)
					.toString();
		if ("SUB".equals(auth))
			operate = (new StringBuilder()).append("mgr-").append(operate)
					.toString();
		return wfObjOpSingle(operate, lf_Bean, lrUpdateId);
	}

	public String redirectToUpdateAction() {
		if (srcAction != null && !srcAction.equals("")) {
			if (srcAction.equals("allLeaveSearch"))
				return "gotoAllLeaveSearch";
			if (srcAction.equals("deptLeaveSearch"))
				return "gotoDeptLeaveSearch";
			if (srcAction.equals("myLeaveSearch"))
				return "gotoMyLeaveSearch";
		}
		return "gotoLeaveAdd";
	}

	public void validate() {
		validateDate(es_Bean);
		validateLRStatus(es_Bean);
	}

	public ExaminSearchBean getEs_Bean() {
		return es_Bean;
	}

	public void setEs_Bean(ExaminSearchBean es_Bean) {
		this.es_Bean = es_Bean;
	}

	public Pager getPage() {
		return page;
	}

	public void setPage(Pager page) {
		this.page = page;
	}

	public String getActionSrc() {
		return actionSrc;
	}

	public void setActionSrc(String actionSrc) {
		this.actionSrc = actionSrc;
	}

	public int getGmanager() {
		return gmanager;
	}

	public void setGmanager(int gmanager) {
		this.gmanager = gmanager;
	}

	public String getSrcAction() {
		return srcAction;
	}

	public void setSrcAction(String srcAction) {
		this.srcAction = srcAction;
	}

	public String getInfoMeg() {
		return infoMeg;
	}

	public void setInfoMeg(String infoMeg) {
		this.infoMeg = infoMeg;
	}

	public String getApproveOper() {
		return approveOper;
	}

	public void setApproveOper(String approveOper) {
		this.approveOper = approveOper;
	}

	public LeaveFormBean getLf_Bean() {
		return lf_Bean;
	}

	public void setLf_Bean(LeaveFormBean lf_Bean) {
		this.lf_Bean = lf_Bean;
	}

	public String getLrUpdateId() {
		return lrUpdateId;
	}

	public void setLrUpdateId(String lrUpdateId) {
		this.lrUpdateId = lrUpdateId;
	}

	public String getRole() {
		return role;
	}

	public void setRole(String role) {
		this.role = role;
	}

	public String getRejectLog() {
		return rejectLog;
	}

	public void setRejectLog(String rejectLog) {
		this.rejectLog = rejectLog;
	}

	private static final long serialVersionUID = 1L;
	private ExaminSearchBean es_Bean;
	private Pager page;
	private int gmanager;
	private String srcAction;
	private String actionSrc;
	private String infoMeg;
	private String approveOper;
	private String rejectLog;
	private LeaveFormBean lf_Bean;
	private String lrUpdateId;
	private String role;
}
